﻿using AutoMapper;
using B.S.BaseData.Domain.Entities;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interfaces;
using B.S.BaseData.Write.API.Command.RoleCommand;
using MediatR;

namespace B.S.BaseData.Write.API.CommandHandler.RoleHandler
{
    public class DelRoleHandler : IRequestHandler<DelRoleCommand, APIResult<object>>
    {
        private readonly IBaseRepository<Role> roleRep;
        private readonly IMapper mapper;

        public DelRoleHandler(IBaseRepository<Role> roleRep,IMapper mapper)
        {
            this.roleRep = roleRep;
            this.mapper = mapper;
        }
        public async Task<APIResult<object>> Handle(DelRoleCommand request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object>();
            var role = roleRep.GetAll().Where(x=>x.RoleId==request.RoleId).FirstOrDefault();
            role.IsDeleted = true;
            roleRep.Update(role);
            result.Code=APIEnum.Success;
            result.Msg = "删除成功";
            return await Task.FromResult(result);
        }
    }
}
